local skel = fk.CreateSkill {
  name = "emo__anqu_copy",
  tags = { Skill.Switch },
  max_branches_use_time = {
    ["yang"] = {
      [Player.HistoryPhase] = 1
    },
    ["yin"] = {
      [Player.HistoryPhase] = 1
    },
  }
}

Fk:loadTranslationTable{
  ["emo__anqu_copy"] = "暗取",
  [":emo__anqu_copy"] = "转换技，出牌阶段各线一次：阳：你可以将一张黑色牌当【瞒天过海】使用；阴：你可以将一张红色牌当【顺手牵羊】使用。",
}

skel:addEffect("viewas", {
  anim_type = "control",
  pattern = "snatch,underhanding",
  prompt = function(self, player)
    return "#emo__anqu-"..player:getSwitchSkillState(skel.name, false, true)
  end,
  handly_pile = true,
  filter_pattern = function (self, player, card_name)
    return {
      max_num = 1,
      min_num = 1,
      pattern = (player:getSwitchSkillState(skel.name) == fk.SwitchYang) and ".|.|black" or ".|.|red",
    }
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard(player:getSwitchSkillState(skel.name) == fk.SwitchYang and "underhanding" or "snatch")
    card.skillName = skel.name
    card:addSubcard(cards[1])
    return card
  end,
  history_branch = function(self, player, data)
    return player:getSwitchSkillState(skel.name, false, true)---@type string
  end,
  enabled_at_play = function (self, player)
    local state = player:getSwitchSkillState(skel.name, false, true)---@type string
    return skel:withinBranchTimesLimit(player, state, Player.HistoryPhase)
  end,
  enabled_at_response = Util.FalseFunc,
})

skel:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name, true, true)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player.room:handleAddLoseSkills(player, "-" .. skel.name)
  end,
})

return skel
